<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>{$lang.add}|{$lang.edit}</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<include file="common/ace-tag"/>
	</head>
	<link rel="stylesheet" href="/static/plugin/ace/css/chosen.css" />
	<script src="/static/plugin/ace/js/chosen.jquery.min.js"></script>
	<script src="/static/plugin/ace/js/jquery.autosize.min.js"></script>
	<script src="/static/plugin/ace/js/jquery.inputlimiter.1.3.1.min.js"></script>
	<style>
		body{
			background-color:#fff
		}
		.yui_right{
			float: right;
			margin-bottom: 10px;
		}
		#content {
			width: 95%;
			height: 300px;
		}
	</style>
	<body >
	<div class="layui-form">
		<div class="widget-main">
			<input type="hidden" name="id" value="{$data.id}"/>

			<div style="margin-bottom: 20px">
				<button class="btn btn-primary" id="save" style="float: left;margin-right: 40px">
					<i class="icon-plus align-top bigger-125"></i>
					{$lang.save}
				</button>
				<input type="checkbox" name="status" checked lay-skin="switch" lay-text="{$lang_field.on}|{$lang_field.off}">
				<br>
			</div>

			<div>
				<label >{$lang_field['title']}</label>
				<input type="text" name="title" placeholder="{$lang_field['title']}" class="form-control" value="{$data.title}"/>
				<br>
			</div>

			<div>
				<label >{$lang_field['sub_title']}</label>
				<input type="text" name="sub_title" placeholder="{$lang_field['sub_title']}" class="form-control" value="{$data.sub_title}"/>
				<br>
			</div>

			<div>
				<label >{$lang_field.tags}</label>
				<select class="form-control" name="tag" lay-search>
					<foreach name="tags" item="l">
						<eq name="$data.tag" value="$l.code">
							<option value="{$l.code}" selected>{$l.name}</option>
							<else/>
							<option value="{$l.code}">{$l.name}</option>
						</eq>
					</foreach>
				</select>
				<br>
			</div>

			<div>
				<label >{$lang_field['label']}</label>
				<input type="text" name="label" placeholder="{$lang_field['label']}" class="form-control" value="{$data.label}"/>
				<br>
			</div>

			<div style="margin-top: 10px">
				<label >{$lang_field['content']}{$data['status']}</label>
				<textarea id="content">{:htmlspecialchars_decode($data.content)}</textarea>
				<br>
			</div>

		</div>
	</div>

	</body>
	<include file="common/ueditor"/>
	<script>
		$(function () {

        	  <?php if ($data['status']==1) { ?>
                $("input:checkbox[name='status']").prop("checked", true);
			  <?php } else if ($data['status']==0 && !empty($data['id'])) { ?>
                $("input:checkbox[name='status']").prop("checked", false);
             <?php }  ?>

            layui.use(['form'], function(){
            });

            ue.ready(function() {
                $("#edui1").css('width','100%');
                $("#edui1_iframeholder").css('width','100%');
                $(".layui-form-select").css('z-index','9999');
            });


            //新增
            $("#save").on('click' , function(){
               let id=$("input[name='id']").val();
                let content=ue.getContent();
                let status = 0;
				if ($("input:checkbox[name='status']").prop('checked'))
                    status = 1;
                let title = $("input[name='title']").val();
                let sub_title = $("input[name='sub_title']").val();
                let label = $("input[name='label']").val();
                let tag=$("select[name='tag']").val();
                let loading = layer.load(1, {
                    shade: [0.1,'#fff']
                });
				//ajax提交数据
                $.post("{$__url}",
                    {
                        method:'{$method}',
                        id:id,
                        title:title,
                        sub_title:sub_title,
                        label:label,
                        tag:tag,
                        content:content,
                        status:status
                    },
                    function(data,status){
                        if (data['code']==1){
                            layer.open({
                                title: '{$lang.notice}',
                                content: '{$lang.op_success}'
                                ,yes: function(index, layero){
                                    //关闭本子页面 & 触发重新查询
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                                    let node = window.parent.document.getElementById("npe_search");
                                    node.click();
                                }
                            });
						}else{
                            layer.msg(data['msg']);
						}
                        layer.close(loading);
                	}, "json"
                );
            });

        });
	</script>

</html>
